package com.xiaoyu.base.entity;

import androidx.annotation.NonNull;
import androidx.room.Entity;
import androidx.room.Ignore;
import androidx.room.Index;
import androidx.room.PrimaryKey;

import java.util.Objects;

import in.srain.cube.request.JsonData;

@Entity(tableName = "user_kv")
public class UserKvEntity {

    @PrimaryKey
    @NonNull
    private String key;
    private String value;

    @Ignore
    public UserKvEntity() {
        key = "";
        value = "";
    }

    public static UserKvEntity fromJson(JsonData jsonData) {
        String key = jsonData.optString("key");
        String value = jsonData.optString("value");
        return new UserKvEntity(key, value);
    }

    public UserKvEntity(@NonNull String key, String value) {
        this.key = key;
        this.value = value;
    }

    @NonNull
    public String getKey() {
        return key;
    }

    public void setKey(@NonNull String key) {
        this.key = key;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof UserKvEntity)) {
            return false;
        }
        UserKvEntity that = (UserKvEntity) o;
        return Objects.equals(key, that.key) &&
                Objects.equals(value, that.value);
    }

    @Override
    public int hashCode() {
        return Objects.hash(key, value);
    }
}
